package com.mpgame;

import java.io.IOException;

import com.mpgame.common.constants.Constants;
import com.mpgame.common.network.GrpcServer;
import com.mpgame.common.utils.ConsulUtil;
import com.mpgame.common.utils.Log;
import com.mpgame.database.mysql.manager.MySqlMgr;
import com.mpgame.database.redis.manager.RedisMgr;
import com.mpgame.mq.MessageQueueConsumer;
import com.mpgame.service.BattleSvc;

public class BattleServer 
{
    public static void main( String[] args ) throws IOException, InterruptedException
    {
        MySqlMgr.getInstance().initGame();
        RedisMgr.getInstance().init();
        if(MySqlMgr.getInstance().testConnection("game")) Log.warn("连接成功！");
        else Log.err("连接失败！");
        MessageQueueConsumer.getInstance().start();
        int port = Constants.CPorts.BATTLE_GRPC_PORT;
        GrpcServer server = new GrpcServer(Constants.CPorts.BATTLE_GRPC_PORT).registService(BattleSvc.GetInstance());
        ConsulUtil.registerAgentService("battle-service", port);
        server.start();
        server.blockUntilShutdown();
    }
}
